<?php 
include_once($req_path."includes/ini.php");
include($req_path."./includes/db2.php");

class M_Menu extends DB2{
    private $rowCount=0;
    public $table_name="";
	
    function M_Menu(){
		parent::__construct();
	   
    }
	function loadUserProfile($did=0){
        
        $sqlscript= "SELECT u.id, u.username,u.password ,u.name
					, g.name as groupname
					, d.name as departmentname
					 ";
		$sqlscript.= " FROM tb_user u ";
		$sqlscript.= " LEFT JOIN tb_group g on g.id = u.gid ";
		$sqlscript.= " LEFT JOIN tb_department d on d.id = u.did ";
		$sqlscript.= " WHERE 1=1 ";
		
		if ($did!=0){
			$sqlscript.= " and u.id = ".$did ;
		}
        
        $result = $this->ExecuteData($sqlscript);
        $this->rowCount = $result->RecordCount();
        return $result->FetchRow();
    }
	function getCurrentYearTerm(){
		$sql = "SELECT name, value
				FROM tb_system_config  
				WHERE name IN ( 'CURR_YEAR' ) ";
		  
		$result = $this->ExecuteData($sql);	
		$row = $result->FetchRow();
		
		
		$sql = "SELECT name, (SELECT name from tb_term where id = value) value
				FROM tb_system_config  
				WHERE name IN ( 'CURR_TERM' ) ";
				
		$result2 = $this->ExecuteData($sql);	
		$row2 = $result2->FetchRow();
		return array('Year'=>$row['value'] +543, 'Term'=>$row2['value']);;
	}		
	function getUserAuthen($id){
		$sql = "SELECT s.name_eng,g.v, url, type , s.name
				From tb_user u
				left join tb_group_permission g on u.gid= g.gid
				LEFT join tb_screen_permission s on s.id=g.sid
				where u.id=".$id . " and g.v=1 order by s.id asc ";
				
		$result = $this->ExecuteData($sql);
        $this->rowCount = $result->RecordCount();
		 
        return $result;
	}
}
?>
